package com.yunji.app.common;

import com.github.pagehelper.page.PageMethod;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.model.params.NoticeParams;
import com.yunji.common.model.vo.NoticeVO;
import com.yunji.system.service.NoticeService;
import com.yunji.system.service.NoticeUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "移动端-通知管理")
@RestController
@RequestMapping("/gateway/notice")
public class GateWayNoticeController {

    @Resource
    NoticeService noticeService;

    @Resource
    NoticeUserService noticeUserService;

    @ApiOperation("通知列表")
    @GetMapping("/noticeList")
    public Response<List<NoticeVO>> noticeList(NoticeParams params){
        PageMethod.startPage(params.getPageNum(), params.getPageSize());
        return ResponseHelper.successWithPage(noticeUserService.pageList(params));
    }

    @ApiOperation("通知详情")
    @GetMapping("/getInfo/{id}")
    public Response<Map<String, Object>> getInfo(@PathVariable("id") Long id){
        return ResponseHelper.success(noticeService.getInfo(id));
    }

    /**
     * 获取未读消息个数
     *
     * @return
     */
    @GetMapping("/unread")
    @ApiOperation("获取未读消息个数")
    public Response<Integer> unread() {
        return ResponseHelper.success(noticeUserService.countUnread());
    }

    /**
     * 当前员工消息全部可读
     *
     * @return
     */
    @PutMapping("/read")
    @ApiOperation("一键已读")
    public Response<String> read() {
        noticeUserService.allRead();
        return ResponseHelper.success("阅读成功");
    }

}
